package _interview75;

import _object.TreeNode;

/**
 * 1448. 统计二叉树中好节点的数目
 */
public class No1448 {
    private int ans = 0;

    public int goodNodes(TreeNode root) {
        dfs(root, root.val);
        return ans;
    }

    private void dfs(TreeNode root, int maxVal) {
        if (root == null) return;
        if (root.val >= maxVal) {
            ans++;
            maxVal = root.val;
        }
        dfs(root.left, maxVal);
        dfs(root.right, maxVal);
    }
}
